<template>
  <div class="caseManage">
    <el-tabs v-model="activeName" type="card" class="elTabs">
      <el-tab-pane name="first">
        <div slot="label" class="pageHeader">处置时限管理</div>
      </el-tab-pane>
    </el-tabs>
    <!-- 搜索查询 -->
    <div class="container">
      <div class="searchBar" v-show="showSearch">
        <div class="searchForm">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            label-width="80px"
          >
            <el-form-item label="角色名称:" prop="roleName">
              <el-input
                v-model.trim="queryParams.roleName"
                placeholder="请输入角色名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="处置类别:" prop="limitType">
              <el-select
                v-model="queryParams.limitType"
                placeholder="请选择处置类别"
                clearable
              >
                <el-option
                  v-for="dict in dict.type.limit_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                /> </el-select
            ></el-form-item>
          </el-form>
        </div>
        <div class="searchButtons">
          <el-button class="searchButton" @click="handleQuery">搜索</el-button>
          <el-button class="resetButton" @click="resetQuery">重置</el-button>
        </div>
      </div>
      <!-- 新增、批量删除、导入、导出 -->
      <div class="addDeleteBar">
        <el-button class="addButton" @click.native="handleAdd"
          ><span class="plus">+</span>新增</el-button
        >
        <el-button
          @click="handleDelete"
          :class="!multiple ? 'deleteButton' : 'allDeleteButton'"
          :disabled="multiple"
          icon="el-icon-delete"
          >批量删除</el-button
        >
        <!-- <el-button class="addButton" icon="el-icon-download">导入</el-button>
      <el-button class="addButton" icon="el-icon-upload2">导出</el-button> -->
      </div>
      <!-- 表单选择清空 -->
      <div class="tableSelectArea">
        <div>
          <div class="iconInfo el-icon-info"></div>
          <span class="infoText">已选择</span>
          <span class="infoText infoActive" v-text="selectedNum"></span>
          <span class="infoText">项</span>
          <span class="infoButton" @click="clearSelect">清空</span>
        </div>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </div>
      <div class="table">
        <el-table
          ref="multipleTable"
          class="tableArea"
          :data="caseList"
          v-loading="loading"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="43" align="center">
          </el-table-column>
          <el-table-column
            type="index"
            label="序号"
            width="70"
            align="center"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
          <el-table-column
            label="角色名称"
            prop="roleName"
            :show-overflow-tooltip="true"
            align="center"
            width="150"
          >
          </el-table-column>
          <el-table-column
            prop="managementType"
            label="处置类别"
            align="center"
            :show-overflow-tooltip="true"
          >
            <template v-slot="scope">
              <dict-tag
                :options="dict.type.limit_type"
                :value="scope.row.limitType"
              ></dict-tag> </template
          ></el-table-column>
          <el-table-column
            prop="timeLimit"
            label="处置时限"
            align="center"
            :show-overflow-tooltip="true"
          >
            <template v-slot="scope">
              <span>{{ scope.row.timeLimit }}</span>
            </template></el-table-column
          >
          <el-table-column label="操作" width="150" align="left" fixed="right">
            <template slot-scope="scope">
              <div class="tableButtonArea">
                <el-button
                  type="text"
                  class="operationButton"
                  @click="handleUpdate(scope.row)"
                  >设置</el-button
                >
                <el-button
                  type="text"
                  class="operationButton"
                  @click="handleDelete(scope.row)"
                  >删除</el-button
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="tableFooter">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <caseManageModal
      ref="caseManageModal"
      :modalType.sync="modalType"
      :id="id"
      @fatherMethod="fatherMethod"
    ></caseManageModal>
  </div>
</template>

<script>
import {
  listTime,
  delTime,
  getTime,
  addTime,
  updateTime,
} from "@/api/timeLimit/time";
import { fatherMethod } from "../../../utils/commonMethods";
import caseManageModal from "./components/caseManageModal.vue";
import { MODALTYPE, PAGESIZE, PAGENUM } from "../../../utils/variable";
export default {
  dicts: ["case_state", "management_type", "time_type", "limit_type"],
  data() {
    return {
      loading: false,
      activeName: "first",
      // 非多个禁用
      multiple: true,
      modalType: undefined,
      selectedNum: 0,
      id: undefined,
      dateRange: [],
      ids: [],
      // 查询参数
      queryParams: {
        pageNum: PAGENUM,
        pageSize: PAGESIZE,
        roleName: undefined,
        limitType: undefined,
      },
      // 总条数
      total: 0,
      //  显示搜索条件
      showSearch: true,
      caseList: [],
    };
  },
  components: { caseManageModal },
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    fatherMethod,
    /** 查询处置时限列表 */
    getList() {
      this.loading = true;
      listTime(this.queryParams).then((response) => {
        this.caseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    //清空列表选择
    clearSelect() {
      this.$refs.multipleTable.clearSelection();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.modalType = MODALTYPE["新增"];
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.modalType = MODALTYPE["修改"];
      this.id = row.id;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      let num = this.selectedNum;
      if (row.id) {
        num = 1;
      }
      this.$modal
        .confirm("是否确认删除" + num + "件处置时限数据")
        .then(function () {
          return delTime(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang='scss' scoped >
@import "../../../assets/styles/variables.scss";
.caseManage {
  height: 100%;
  .tableFooter {
    text-align: right;
    justify-content: flex-end;
    // margin-top: 25px;
    margin-right: 35px;
    // width: 100%;
    ::v-deep .btn-prev {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .btn-next {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .el-pager li {
      background-color: #fff;
      border: 1px solid #d4d3d3;
      font-size: 12px;
      font-family: $font-family;
      font-weight: 400;
      color: #5a5b5d;
    }
  }
  .el-form-item__label {
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    font-size: $form-label-font-size;
    color: $form-label-color;
  }

  .el-input__inner {
    font-size: $form-content-font-size;
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    // color: #AEAFB0;
  }
  .el-tabs--card > .el-tabs__header .el-tabs__nav {
    border: 0px;
  }
  ::v-deep .el-tabs--card .el-tabs__header {
    background-color: #e4e7ed;
  }
  ::v-deep.el-tabs--card .el-tabs__header .el-tabs__item {
    border-radius: 10px solid black;
    background-color: #fff;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #053ef6;
    line-height: 48px;
    margin-top: 0;
  }
  .el-tabs--card {
    margin-left: 10px;
    border: 0px !important;
  }
}
</style>
